import { ElMessage } from "element-plus"
import storage from "@/utils/storage"
export default function useFn() {
    function copyToClipboard(text) {
        const textarea = document.createElement('textarea')
        textarea.value = text
        document.body.appendChild(textarea)
        textarea.select()
        document.execCommand('copy')
        document.body.removeChild(textarea)
        ElMessage({
            type: 'success',
            message: '已复制'
        })
    }
    function add(val1, maxval, minval, vm, t) {
        debugger
        vm.proxy.total += 1
        if (val1 >= maxval) {
            vm.proxy.total = maxval
            ElMessage({
                type: 'warning',
                message: t("tips.over")
            })
        }
    }
    function minus(val1, maxval, minval, vm, t) {
        vm.proxy.total -= 1
        if (minval && val1 <= minval) {
            vm.proxy.total = minval
            ElMessage({
                type: 'warning',
                message: `${t("tips.buyNums")}${minval}${t("tips.jian")}`
            })
        } else {
            console.log(vm)
            if (val1 <= 1) {
                vm.proxy.total = 1
                ElMessage({
                    type: 'warning',
                    message: t('tips.min')
                })
            }
        }

    }

    function LocalCarSave(item) {
        const list = storage.getStorage('carInfo')
        if (list && list.length) {
            list.push(item)
            storage.setStorage('carInfo', list)
        } else {
            let arr = []
            arr.push(item)
            storage.setStorage('carInfo', arr)
        }
    }
    return {
        copyToClipboard,
        add,
        minus,
        LocalCarSave
    }
}




